﻿using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Collections.Generic;

namespace ERModelData
{
    /// <summary>Панель отражающая свойства оьъектов</summary>
    class Property : TreeView
    {
        /// <summary>Конструктор класса</summary>
        public Property()
        {
            MinWidth = 200;
        }

        /// <summary>Отображение свойств выделенной сущности</summary>
        /// <param name="select">Выделенная сущность</param>
        public void SelectEssence(Essence select)
        {
            this.Items.Clear();

            TreeViewItem nameEssence = new TreeViewItem();
            nameEssence.Header = CreateTextBox(select.name);

            Label label = new Label();
            label.Content = "Толщина рамки: ";

            TextBox text = new TextBox();
            text.Text =  select.BorderThickness.Bottom.ToString();


            Binding binding1 = new Binding("BorderThickness.Bottom");
            binding1.Mode = BindingMode.TwoWay;
            binding1.Source = select;           
            text.SetBinding(TextBox.TextProperty, binding1);

            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.Children.Add(label);
            panel.Children.Add(text);

            TreeViewItem maket = new TreeViewItem();
            maket.Header = "Визуальные свойства";
            maket.Items.Add(panel);

            Label l = new Label();
            l.Content = "СВОЙСТВА!!!";


            this.Items.Add(nameEssence);
            this.Items.Add(maket);
        }

        /// <summary>Очистка панели свойств</summary>
        public void ClearProperty()
        {
            this.Items.Clear();
        }
        
        /// <summary>[Service Function] Создание контрола редактирования текста</summary>
        /// <param name="source">Прототип свойства</param>
        /// <returns>Созданый контрол</returns>
        private StackPanel CreateTextBox(Label source)
        {
            Label label = new Label();
            label.Content = "Имя: ";
            
            TextBox text = new TextBox();
            text.Text = source.Content.ToString();
            
            Binding binding = new Binding("Content");
            binding.Mode = BindingMode.TwoWay;
            binding.Source = source;
            text.SetBinding(TextBox.TextProperty, binding);
            
            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.Children.Add(label);
            panel.Children.Add(text);

            return panel;
        }
    }
}
